import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/states/states_model/user.dart';
import 'package:qgchat/widgets/tipsDialog.dart';

class UserTab extends StatelessWidget {
  final String title;
  final Function onPressed;
  final String iconPath;

  const UserTab({this.onPressed, this.title, this.iconPath, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: w100(context),
      height: px(120),
      color: Colors.white,
      child: FlatButton(
        padding: EdgeInsets.all(px(0)),
        onPressed: () {
          final user = Provide.value<UserState>(context);
          final info = user.info;
          final isLogin = info != null;
          if (isLogin) {
            onPressed();
          } else {
            TipsDialog.login(
              context,
              () {
                goPage(context, '/phoneLogin');
              },
            );
          }
        },
        child: Container(
          width: px(690),
          height: px(120),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                child: Row(
                  children: <Widget>[
                    /// icon
                    Container(
                      width: px(60),
                      height: px(60),
                      child: Image.asset(iconPath),
                    ),

                    /// title
                    Container(
                      margin: EdgeInsets.only(left: px(26)),
                      child: Text(
                        title,
                        style: TextStyle(fontSize: px(34)),
                      ),
                    ),
                  ],
                ),
              ),

              /// 右箭头
              Container(
                child: Icon(
                  Icons.navigate_next,
                  size: 26,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
